package quick.portal.activity;

import quick.common.AppContext;
import quick.portal.R;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

public class QuickNotification {
	
	private static final int id_notice = 1;
	private static final int id_todo = 2;
	private static final int id_email = 3;
	
	@SuppressWarnings("deprecation")
	public void showNotification(int id,String title,String contentTitle,String contentText,Class<?> target)
	{
		//定义NotificationManager
        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager)AppContext.getInstance().getSystemService(ns);
        
        //定义通知栏展现的内容信息
        Notification notification = new Notification();
        notification.icon = R.drawable.ic_portal;
        notification.tickerText = title;
        notification.when = System.currentTimeMillis();
        
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
         
        //定义下拉通知栏时要展现的内容信息
        Context context = AppContext.getInstance();
        Intent notificationIntent = new Intent(context, target);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0,notificationIntent, 0);
        notification.setLatestEventInfo(context, contentTitle, contentText,contentIntent);
         
        //用mNotificationManager的notify方法通知用户生成标题栏消息通知
        mNotificationManager.notify(id, notification);
	}
	
	public void showNoticeNotification(String contentTitle,String contentText)
	{
		String title = "你收到新的公告消息";
		this.showNotification(id_notice, title, contentTitle, contentText, MainActivity.class);
	}
	
	public void showTodoNotification(String contentTitle,String contentText)
	{
		String title = "你收到新的待办要处理";
		this.showNotification(id_todo, title, contentTitle, contentText, MainActivity.class);
	}
	
	public void showEmailNotification(String contentTitle,String contentText)
	{
		String title = "你收到新的邮件要处理";
		this.showNotification(id_email, title, contentTitle, contentText, MainActivity.class);
	}
}
